package com.zzyy.study.controller;

import com.zzyy.study.cache.Cache;
import com.zzyy.study.cache.ClearAndReloadCache;
import com.zzyy.study.entities.Result;
import com.zzyy.study.entities.User;
import com.zzyy.study.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @auther zzyy
 * @create 2025-03-15 16:43
 */
@RestController
public class UserController
{
    @Resource
    private UserService userService;

    @PostMapping("/user/insert")
    public Result insert(@RequestBody User user){
        return userService.insert(user);
    }

    @DeleteMapping("/user/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return userService.delete(id);
    }

    @PostMapping("/user/updateData")
    @ClearAndReloadCache(name = "get_method")
    public Result updateData(@RequestBody User user){
        return userService.update(user);
    }

    // http://localhost:9993/user/get/1
    @GetMapping("/user/get/{id}")
    @Cache(name = "get_method") //使用RedisConfig2配置类
    public Result get(@PathVariable("id") Integer id){
        return userService.get(id);
    }

}
